package org.example.lethear.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 角色实体类
 */
@Entity
@Table(name = "roles")
@Data
@EqualsAndHashCode(callSuper = false)
@EntityListeners(AuditingEntityListener.class)
public class Role {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(name = "role_name", unique = true, nullable = false, length = 50)
    private String roleName;
    
    @Column(length = 200)
    private String description;
    
    @Column(columnDefinition = "JSON")
    private String permissions;
    
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;
    
    // 构造方法
    public Role() {}
    
    public Role(String roleName, String description, String permissions) {
        this.roleName = roleName;
        this.description = description;
        this.permissions = permissions;
    }
    
    // 便利方法
    public boolean isAdmin() {
        return "ADMIN".equals(roleName);
    }
    
    public boolean isUser() {
        return "USER".equals(roleName);
    }
} 